<template>
	<view >
		  <u--input
		    placeholder="群名称"
		    border="surround"
		    v-model="groupName"
			style="margin: 20rpx;"
		  ></u--input>
		  <u--textarea v-model="groupInfo" placeholder="群简介"  style="margin: 20rpx;"></u--textarea>
		  <u-button type="success" text="创建" style="width: 95vw;" @click="createGroup"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				groupName:'',
				groupInfo:'',
				timer:null
			}
		},
		destroyed() {
			this.timer=null
		},
		methods: {
			createGroup(){
				if(!this.groupInfo || !this.groupInfo) {
				
					uni.showToast({
						title:'请将信息补充完整' //只显示错误时候的消息
					})
					return
				}
				var user_ids=[]//默认自己创建群自己也在群里
				this.$store.state.group.groupMembersList.forEach((item)=>{
					user_ids.push(item.id)
				})
				this.$myRquest({
					url:'/group/create',
					method:'post',
					data:{
						group_name:this.groupName,
						group_desc:this.groupInfo,
						user_ids:user_ids					
					}
				}).then(res=>{					
					this.resetData()			
					uni.showToast({
						title:'创建成功!' //只显示错误时候的消息
					})
					this.timer=setTimeout(()=>{
						uni.switchTab({
							url:'/pages/firendsList/index'
						})
					},1000)
				})
			},
			resetData(){
				//this.$options.data 获取该组件初始化时中的data
				Object.assign(this.$data, this.$options.data()) //重置组件data中所有的数据 
			}
		}
	}
</script>

<style>

</style>
